package com.example.baserecyclerviewadapterdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.example.baserecyclerviewadapterdemo.R;
import com.example.baserecyclerviewadapterdemo.activity.multi.MultiItemBinderActivity;
import com.example.baserecyclerviewadapterdemo.activity.multi.MultiItemDelegateActivity;
import com.example.baserecyclerviewadapterdemo.activity.multi.MultiItemProviderActivity;
import com.example.baserecyclerviewadapterdemo.activity.multi.MultiItemQuickActivity;
import com.example.baserecyclerviewadapterdemo.adapter.MultiItemEntityAdapter;
import com.example.baserecyclerviewadapterdemo.data.DataServer;

public class MultiItemActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private MultiItemEntityAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_multi_item);

        final Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL));
        adapter = new MultiItemEntityAdapter(DataServer.getMultiItemAdapterEntities());
        adapter.setAnimationEnable(true);
        recyclerView.setAdapter(adapter);

        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                switch (position) {
                    case 0:
                        startActivity(new Intent(MultiItemActivity.this, MultiItemBinderActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MultiItemActivity.this, MultiItemQuickActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(MultiItemActivity.this, MultiItemDelegateActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(MultiItemActivity.this, MultiItemProviderActivity.class));
                        break;
                    default:
                        break;
                }
            }
        });
    }


}
